package com.baoxin.chenxixc4coach.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.baoxin.chenxixc4coach.R;
import com.baoxin.chenxixc4coach.bean.OrderDetail;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;

import java.util.List;

public class OrderDetailAdapter extends RecyclerView.Adapter<OrderDetailAdapter.ViewHolder> {

    private List<OrderDetail> orderDetailList;
    private Context context;

    public OrderDetailAdapter(Context context) {
        this.context = context;
    }

    public void setData(List<OrderDetail> orderDetailList) {
        this.orderDetailList = orderDetailList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.order_detail_item, parent, false);
        final ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        OrderDetail orderDetail = orderDetailList.get(position);
        Glide.with(context)
                .load(R.drawable.default_)
                .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                .into(holder.icon);
        holder.name.setText(orderDetail.getName());
        holder.time.setText(orderDetail.getTime());
        if (orderDetail.isLianxi()) {
            holder.lianxi.setVisibility(View.VISIBLE);
        } else {
            holder.lianxi.setVisibility(View.GONE);
        }
        if (orderDetail.isPingjia()) {
            holder.pingjia.setVisibility(View.VISIBLE);
        } else {
            holder.pingjia.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        return orderDetailList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        View itemVIew;
        ImageView icon;
        TextView name;
        ImageView lianxi;
        ImageView pingjia;
        TextView time;

        public ViewHolder(View itemView) {
            super(itemView);
            this.itemVIew = itemView;
            icon = itemView.findViewById(R.id.icon);
            name = itemView.findViewById(R.id.name);
            lianxi = itemView.findViewById(R.id.lianxi);
            pingjia = itemView.findViewById(R.id.pingjia);
            time = itemView.findViewById(R.id.time);
        }
    }
}
